﻿using FanaticRock.Core.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FanaticRock.Helpers
{
    internal class BvidHelper
    {
        ///<summary>获得音频的基本路径。</summary>
        public static async Task<string> GetAudioBaseUrl(string bvid)
        {
            var view = await FanaticRock.MediaSource.BilibiliAPI.API.WebInterface.View.InvokeByBvid(bvid);

            var cid = view.Data.Pages.FirstOrDefault().Cid;

            var playUrlDto = await FanaticRock.MediaSource.BilibiliAPI.API.Player.Wbi.PlayUrl.Invoke(new MediaSource.BilibiliAPI.RequestVo.Player.Wbi.PlayUrlRequestVo()
            {
                Bvid = bvid,
                Cid = cid,
                Fnval = MediaSource.BilibiliAPI.Enums.FnvalEnum.Fnval_DASH,
            });

            if (playUrlDto.Data.Dash == null) return null;

            var audio = playUrlDto.Data.Dash.Audio.FirstOrDefault();

            var baseUrl = audio.BaseUrl;
            return baseUrl;
        }

    }
}
